Fs = 1000;            % Sampling frequency                    
T = 1/Fs;             % Sampling period       
L = 1500;             % Length of signal
t = (0:L-1)*T;        % Time vector
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);

f = Fs*(0:(L/2))/L;
Y = fft(S);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);

subplot(2,2,1)
plot(1000*t(1:50),S(1:50))
title('original signal')
xlabel('t (milliseconds)')
ylabel('S(t)')

subplot(2,2,2)
plot(f,P1) 
title('original fft result')
xlabel('f (Hz)')
ylabel('|P1(f)|')

Y1=Y;
Y1(1,1400:end)=0;
Y1(1,1:100)=0;
S1=ifft(Y1);
S1=real(S1);

Y2 = fft(S1);
P3 = abs(Y2/L);
P4 = P3(1:L/2+1);
P4(2:end-1) = 2*P4(2:end-1);

subplot(2,2,3)
plot(1000*t(1:50),S1(1:50))
title('set frequency to 0')
xlabel('t (milliseconds)')
ylabel('S(t)')

subplot(2,2,4)
plot(f,P4) 
title('set frequency to 0 fft result')
xlabel('f (Hz)')
ylabel('|P1(f)|')


